package org.PISS.viewComponents.fitterProcessing;

import org.PISS.controller.model.Fitter;
import org.PISS.controller.model.Supplier;
import org.PISS.services.DAOService;
import org.PISS.utils.CommonUtil;
import org.primefaces.context.RequestContext;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.util.List;

/**
 * Created by admin on 25.01.14.
 */
@ManagedBean
@ViewScoped
public class FitterTableBean {
    private List<Fitter> fitterList;
    private String name;
    private String information;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInformation() {
        return information;
    }

    public void setInformation(String information) {
        this.information = information;
    }

    public void save(){
        Fitter fitter = new Fitter(name,information,10);
        DAOService.getInstance().getFitterDAO().addFitter(fitter);
        name=null;
        information=null;
        update("add_dialog_form");
        update(CommonUtil.getFullComponentID("dataTable"));
    }

    public List<Fitter> getFitterList() {
        if(fitterList==null){
            fitterList= DAOService.getInstance().getFitterDAO().getFitterList();
        }
        return fitterList;
    }

    public void setFitterList(List<Fitter> fitterList) {
        this.fitterList = fitterList;
    }

    public void update(String id){
        RequestContext.getCurrentInstance().update(id);
    }
}

